package lt.marsrutai.mobile.android.model;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import lt.marsrutai.mobile.android.model.enums.WeekdayType;

/**
 * Represents all arrival times of the week for a particular stop
 * 
 * @author jvalskis
 */
public class StopArrivalTimes {

    /**
     * Multiple days can share the same arrival times - such days can be considered as one day group
     * This map holds common {@link ArrivalTime}s for a each {@link DayGroup} in the week 
     */
    private Map<DayGroup, List<ArrivalTime>> groupedArrivalTimes = new TreeMap<DayGroup, List<ArrivalTime>>();

    /**
     * Adds arrival times for a specific day group
     * 
     * @param dayGroup
     * @param arrivalTimes
     */
    public void addArrivalTimes(DayGroup dayGroup, List<ArrivalTime> arrivalTimes) {
        groupedArrivalTimes.put(dayGroup, arrivalTimes);
    }

    /**
     * Finds arrival times for the provided day
     * 
     * @param day
     * @return Arrival times for the provided day if they exist, <code>null</code> otherwise
     */
    public List<ArrivalTime> getArrivalTimes(WeekdayType day) {
        for (Entry<DayGroup, List<ArrivalTime>> entry : groupedArrivalTimes.entrySet()) {
            if (entry.getKey().contains(day)) {
                return entry.getValue();
            }
        }
        return null;
    }

    /**
     * @return All arrival times. Keyed by {@link DayGroup} with list of {@link ArrivalTime}s as values
     */
    public Set<Entry<DayGroup, List<ArrivalTime>>> getArrivalTimes() {
        return groupedArrivalTimes.entrySet();
    }
}
